//package cn.xie.blog.servergateway.handler;
//
//import cn.xie.blog.model.common.enums.response.ResponseCodeEnum;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import jakarta.annotation.Resource;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.ServletOutputStream;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.security.access.AccessDeniedException;
//import org.springframework.security.web.access.AccessDeniedHandler;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//
///**
// * @description: 权限拒绝处理器
// * @author: xiaoxie
// * @date: 2025/4/30 上午11:02
// **/
//@Component
//public class LoginAccessDefineHandler implements AccessDeniedHandler {
//
//    private final Logger logger = LoggerFactory.getLogger(LoginAccessDefineHandler.class);
//    @Resource
//    private  ObjectMapper objectMapper;
//
//    @Override
//    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
//        logger.info("用户访问被拒绝：{}", request.getRemoteUser());
//        logger.debug("请求URL：{}", request.getRequestURI());
//        logger.debug("异常：{}", accessDeniedException.getMessage());
//
//        response.setContentType("application/json;charset=UTF-8");
//        ServletOutputStream out = response.getOutputStream();
//        out.write(objectMapper.writeValueAsString(ResponseCodeEnum.FORBIDDEN).getBytes(StandardCharsets.UTF_8));
//        out.flush();
//        out.close();
//    }
//}